package com.example.picturestorage.controller;

import com.example.picturestorage.bean.Role;
import com.example.picturestorage.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    //一级缓存需要加事务才有效(因为没有显式调用sqlSession)
    @Transactional
    @GetMapping("/role/{id}")
    public Role findOneRole(@PathVariable("id") Integer id){
        return roleService.findOneRole(id);
    }

    @GetMapping("/roles")
    public List<Role> findRoleList(){
        return roleService.findRoleList();
    }

    @PostMapping("/rolesByCondition")
    public List<Role> findRoleList(@RequestBody Role role){
        return roleService.selectRoleByCondition(role);
    }

    @PostMapping("/updateOneByCondition")
    public int updateOneByCondition(@RequestBody Role role){
        return roleService.updateOneByCondition(role);
    }

}
